import { MongoClient } from "mongodb";

const url = process.env.MONGO_DB_URI;

const mongoClient = new MongoClient(url, {
  serverApi: {
    version: "1",
    strict: true,
    deprecationErrors: true,
  },
});

export async function mongoConnect() {
  try {
    await mongoClient.connect();
    console.log("Connected to MongoDB");
  } catch (err) {
    console.log(err);
  }
}

export async function mongoClose() {
  try {
    await mongoClient.close();
    console.log("Connection to MongoDB closed");
  } catch (err) {
    console.log(err);
  }
}

export default mongoClient;
